package com.nineclock.system.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.excel.ExcelMember;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {
    private List<ExcelMember> list = new ArrayList<>();
    private SysCompanyUserService companyUserService;

    public ExcelMemberListener(SysCompanyUserService companyUserService) {
        this.companyUserService = companyUserService;
    }

    @Override
    public void invoke(ExcelMember excelMember, AnalysisContext analysisContext) {
        list.add(excelMember);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("解析员工excel完毕，员工数据 = " + list);
        companyUserService.handleParsedData(list);
    }
}
